
#include "sqlite3.h"
#include "sqlite3x.hpp"

namespace sqlite3x {

    sqlite3_transaction::sqlite3_transaction(sqlite3_connection &con, bool start) : con(con),intrans(false) {
        if(start) begin();
    }

    sqlite3_transaction::~sqlite3_transaction() {
        if(intrans) {
            try {
                rollback();
            }
            catch(...) {
                return;
            }
        }
    }

    void sqlite3_transaction::begin() {
        con.execute_nonquery("begin;");
        intrans=true;
    }

    void sqlite3_transaction::commit() {
        con.execute_nonquery("commit;");
        intrans=false;
    }

    void sqlite3_transaction::rollback() {
        con.execute_nonquery("rollback;");
        intrans=false;
    }

}
